{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read the input image"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import the needed libraries\n",
    "import tensorflow as tf\n",
    "import tensorflow.contrib.tensorrt as trt # must import this although we will not use it explicitly\n",
    "from tensorflow.python.platform import gfile\n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "import time\n",
    "from matplotlib import pyplot as plt\n",
    "\n",
    "# read the testing images (only for example)\n",
    "img1= Image.open(\"dataset/mnist/testing/0/img_108.jpg\")\n",
    "img2= Image.open(\"dataset/mnist/testing/1/img_0.jpg\")\n",
    "img1 = np.asarray(img1)\n",
    "img2 = np.asarray(img2)\n",
    "input_img = np.concatenate((img1.reshape((1, 28, 28, 1)), \n",
    "                            img2.reshape((1, 28, 28, 1))), \n",
    "                           axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Function to read \".pb\" model (TensorRT model is stored in \".pb\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# function to read a \".pb\" model \n",
    "# (can be used to read frozen model or TensorRT model)\n",
    "def read_pb_graph(model):\n",
    "  with gfile.FastGFile(model,'rb') as f:\n",
    "    graph_def = tf.GraphDef()\n",
    "    graph_def.ParseFromString(f.read())\n",
    "  return graph_def"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Perform inference using TensorRT model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-2-a1064865cc5f>:4: FastGFile.__init__ (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.gfile.GFile.\n",
      "needed time in inference-0:  0.000782012939453125\n",
      "needed time in inference-1:  0.0006928443908691406\n",
      "needed time in inference-2:  0.0006496906280517578\n",
      "needed time in inference-3:  0.0006840229034423828\n",
      "needed time in inference-4:  0.0006887912750244141\n",
      "needed time in inference-5:  0.0005681514739990234\n",
      "needed time in inference-6:  0.0005831718444824219\n",
      "needed time in inference-7:  0.0005865097045898438\n",
      "needed time in inference-8:  0.0007417201995849609\n",
      "needed time in inference-9:  0.0006723403930664062\n",
      "needed time in inference-10:  0.0006170272827148438\n",
      "needed time in inference-11:  0.0006124973297119141\n",
      "needed time in inference-12:  0.0005292892456054688\n",
      "needed time in inference-13:  0.0005846023559570312\n",
      "needed time in inference-14:  0.0006611347198486328\n",
      "needed time in inference-15:  0.0005919933319091797\n",
      "needed time in inference-16:  0.000553131103515625\n",
      "needed time in inference-17:  0.0005233287811279297\n",
      "needed time in inference-18:  0.0005125999450683594\n",
      "needed time in inference-19:  0.0006606578826904297\n",
      "needed time in inference-20:  0.0006861686706542969\n",
      "needed time in inference-21:  0.0006895065307617188\n",
      "needed time in inference-22:  0.0005710124969482422\n",
      "needed time in inference-23:  0.0005686283111572266\n",
      "needed time in inference-24:  0.0007379055023193359\n",
      "needed time in inference-25:  0.0008666515350341797\n",
      "needed time in inference-26:  0.0006678104400634766\n",
      "needed time in inference-27:  0.0007331371307373047\n",
      "needed time in inference-28:  0.0007426738739013672\n",
      "needed time in inference-29:  0.0005896091461181641\n",
      "needed time in inference-30:  0.0007865428924560547\n",
      "needed time in inference-31:  0.0005784034729003906\n",
      "needed time in inference-32:  0.0006244182586669922\n",
      "needed time in inference-33:  0.0005807876586914062\n",
      "needed time in inference-34:  0.0006392002105712891\n",
      "needed time in inference-35:  0.0006310939788818359\n",
      "needed time in inference-36:  0.0005528926849365234\n",
      "needed time in inference-37:  0.0006742477416992188\n",
      "needed time in inference-38:  0.000621795654296875\n",
      "needed time in inference-39:  0.0007097721099853516\n",
      "needed time in inference-40:  0.0006639957427978516\n",
      "needed time in inference-41:  0.0006222724914550781\n",
      "needed time in inference-42:  0.0006463527679443359\n",
      "needed time in inference-43:  0.0006847381591796875\n",
      "needed time in inference-44:  0.0006887912750244141\n",
      "needed time in inference-45:  0.0006015300750732422\n",
      "needed time in inference-46:  0.0005192756652832031\n",
      "needed time in inference-47:  0.0006458759307861328\n",
      "needed time in inference-48:  0.0006835460662841797\n",
      "needed time in inference-49:  0.0005686283111572266\n",
      "average inference time:  0.0006414556503295899\n"
     ]
    }
   ],
   "source": [
    "# variable\n",
    "TENSORRT_MODEL_PATH = './model/TensorRT_model.pb'\n",
    "\n",
    "graph = tf.Graph()\n",
    "with graph.as_default():\n",
    "    with tf.Session(config=tf.ConfigProto(gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.50))) as sess:\n",
    "        # read TensorRT model\n",
    "        trt_graph = read_pb_graph(TENSORRT_MODEL_PATH)\n",
    "\n",
    "        # obtain the corresponding input-output tensor\n",
    "        tf.import_graph_def(trt_graph, name='')\n",
    "        input = sess.graph.get_tensor_by_name('input_tensor_input:0')\n",
    "        output = sess.graph.get_tensor_by_name('output_tensor/Softmax:0')\n",
    "\n",
    "        # in this case, it demonstrates to perform inference for 50 times\n",
    "        total_time = 0; n_time_inference = 50\n",
    "        out_pred = sess.run(output, feed_dict={input: input_img})\n",
    "        for i in range(n_time_inference):\n",
    "            t1 = time.time()\n",
    "            out_pred = sess.run(output, feed_dict={input: input_img})\n",
    "            t2 = time.time()\n",
    "            delta_time = t2 - t1\n",
    "            total_time += delta_time\n",
    "            print(\"needed time in inference-\" + str(i) + \": \", delta_time)\n",
    "        avg_time_tensorRT = total_time / n_time_inference\n",
    "        print(\"average inference time: \", avg_time_tensorRT)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Perform inference using the original tensorflow model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "needed time in inference-0:  0.0009000301361083984\n",
      "needed time in inference-1:  0.0009007453918457031\n",
      "needed time in inference-2:  0.0008113384246826172\n",
      "needed time in inference-3:  0.0006928443908691406\n",
      "needed time in inference-4:  0.0007717609405517578\n",
      "needed time in inference-5:  0.0007328987121582031\n",
      "needed time in inference-6:  0.0006477832794189453\n",
      "needed time in inference-7:  0.0007433891296386719\n",
      "needed time in inference-8:  0.0008635520935058594\n",
      "needed time in inference-9:  0.0007891654968261719\n",
      "needed time in inference-10:  0.0014221668243408203\n",
      "needed time in inference-11:  0.0006916522979736328\n",
      "needed time in inference-12:  0.0006837844848632812\n",
      "needed time in inference-13:  0.0006885528564453125\n",
      "needed time in inference-14:  0.0006639957427978516\n",
      "needed time in inference-15:  0.0006635189056396484\n",
      "needed time in inference-16:  0.0007214546203613281\n",
      "needed time in inference-17:  0.0007011890411376953\n",
      "needed time in inference-18:  0.0007994174957275391\n",
      "needed time in inference-19:  0.0008628368377685547\n",
      "needed time in inference-20:  0.0007817745208740234\n",
      "needed time in inference-21:  0.0008561611175537109\n",
      "needed time in inference-22:  0.0007662773132324219\n",
      "needed time in inference-23:  0.0006921291351318359\n",
      "needed time in inference-24:  0.0007948875427246094\n",
      "needed time in inference-25:  0.0008332729339599609\n",
      "needed time in inference-26:  0.0009150505065917969\n",
      "needed time in inference-27:  0.0009999275207519531\n",
      "needed time in inference-28:  0.000698089599609375\n",
      "needed time in inference-29:  0.0007965564727783203\n",
      "needed time in inference-30:  0.0006709098815917969\n",
      "needed time in inference-31:  0.0008847713470458984\n",
      "needed time in inference-32:  0.0007991790771484375\n",
      "needed time in inference-33:  0.0008256435394287109\n",
      "needed time in inference-34:  0.0008854866027832031\n",
      "needed time in inference-35:  0.0008411407470703125\n",
      "needed time in inference-36:  0.0007293224334716797\n",
      "needed time in inference-37:  0.0007402896881103516\n",
      "needed time in inference-38:  0.0008275508880615234\n",
      "needed time in inference-39:  0.0007765293121337891\n",
      "needed time in inference-40:  0.0008652210235595703\n",
      "needed time in inference-41:  0.0008633136749267578\n",
      "needed time in inference-42:  0.001062631607055664\n",
      "needed time in inference-43:  0.0008845329284667969\n",
      "needed time in inference-44:  0.0009775161743164062\n",
      "needed time in inference-45:  0.0008337497711181641\n",
      "needed time in inference-46:  0.0008544921875\n",
      "needed time in inference-47:  0.0008146762847900391\n",
      "needed time in inference-48:  0.0007350444793701172\n",
      "needed time in inference-49:  0.0007650852203369141\n",
      "average inference time:  0.0008104658126831055\n",
      "TensorRT improvement compared to the original model: 1.2634791076618868\n"
     ]
    }
   ],
   "source": [
    "# variable\n",
    "FROZEN_MODEL_PATH = './model/frozen_model.pb'\n",
    "\n",
    "graph = tf.Graph()\n",
    "with graph.as_default():\n",
    "    with tf.Session() as sess:\n",
    "        # read TensorRT model\n",
    "        frozen_graph = read_pb_graph(FROZEN_MODEL_PATH)\n",
    "\n",
    "        # obtain the corresponding input-output tensor\n",
    "        tf.import_graph_def(frozen_graph, name='')\n",
    "        input = sess.graph.get_tensor_by_name('input_tensor_input:0')\n",
    "        output = sess.graph.get_tensor_by_name('output_tensor/Softmax:0')\n",
    "\n",
    "        # in this case, it demonstrates to perform inference for 50 times\n",
    "        total_time = 0; n_time_inference = 50\n",
    "        out_pred = sess.run(output, feed_dict={input: input_img})\n",
    "        for i in range(n_time_inference):\n",
    "            t1 = time.time()\n",
    "            out_pred = sess.run(output, feed_dict={input: input_img})\n",
    "            t2 = time.time()\n",
    "            delta_time = t2 - t1\n",
    "            total_time += delta_time\n",
    "            print(\"needed time in inference-\" + str(i) + \": \", delta_time)\n",
    "        avg_time_original_model = total_time / n_time_inference\n",
    "        print(\"average inference time: \", avg_time_original_model)\n",
    "        print(\"TensorRT improvement compared to the original model:\", avg_time_original_model/avg_time_tensorRT)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot the prediction result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAEOCAYAAABGscHCAAAABHNCSVQICAgIfAhkiAAAAAlw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TKsu1ly8pT83PXa8vd13KFX1HK+FtgGHCbu9/Q9U40YWZTaRztoTHc+c46+2ZmdwGn0xjyuRb4DHAvsBA4AngRuNDdu/7BW0nfTmeQy7YPUd/KlpV/ghqfu04ud9+R/ujyXpE86Qo/kUwp+UUypeQXyZSSXyRTSn6RTCn5RTKl5BfJ1P8DIMapW3xlKCEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAEOCAYAAABGscHCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAE1RJREFUeJzt3X+QnVV9x/H3J8mSkJhMQCCNGBqxTGtEG22GtoNjwzA4Uenwo2ilUqN1iAp2Sq1OrXYqnY5TYVDE1kGjZMAWY1MTIKY/EqQKpq2UQBVCUSIYEbOTQENJTEhCkm//uM+267LPOTd7fzw3OZ/XzM7dfb73ee7Zm3z2ufee55yjiMDMyjOp6QaYWTMcfrNCOfxmhXL4zQrl8JsVyuE3K5TDb10h6Z2SQtLNR7jfPEnvk3STpAclHayO88EeNdUqU5pugBXvt4Drm25EiXzmt6b9ELgBeAewAPibZptTDp/5rVERcQdwx8jPkg432Jyi+Mw/oKr3vVF9v0zSf0raK+m/Ja2RdGYb+71b0r2SdlXbZ4+635Ck90r6lqRnJO2TtEXSpySdXHNsVcd8QNJzkp6WdLukV/fiObDecvgHnKTrgRuBZ2mdIZ8GLgLulfS6xH5/BSwH9gPrgPuBkT8Ks4B/qY77KuAB4B9ovRL8Q2CTpPnjHPazwBeBVwP/BtxZ7X8vcFaiLd+s/vhc3d5vbX0REf4awC9aQQ1gD/D6UdsF/GVVewKYVrPf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ZOBR4DzgSeA+4NKI+K++NqSGpK3Aooho/IIQSa8Hfgp8aWQpNEnXAjsj4hPVH84TIuKPB6RtV3OEy7b3qG11y8q/kwafu24ud98NTZz5zwJ+EBGPR8QB4CvABQ20Y+BFxD3AzjGbLwBuqb6/hdZ/nr6radtAiIjhiHig+n43MLKsfKPPXaJdjWgi/KcCPx7185M0+ASMI4ANku6XtKzpxoxjzsiyaNXtKQ23Z6zssu39NGZZ+YF57iay3H23NRH+8ZYSGqT+xrMj4rXAG4Erq5e31p4bgZfTWsNxGPhkk42plpVfDVwVEbuabMto47SrkeetifA/Ccwb9fNLgW0NtGNcEbGtut0B3Ebrbcog2T6yQnJ1u6Ph9vyfiNgeEYci4jDwBRp87qpl5VcDt0bEmmpz48/deO1q6nlrIvz3AWdIepmk44C3AWsbaMcLSJpRfRCDpBnAGxi8pcfXAkur75cCdzTYlp8xKMu21y0rT8PP3aAtd9/IFX5VV8angcnAioj4eN8bMQ5Jp9M620NruPOXm2ybpJXAYlpDPrcDHwNuB1YBpwFPAG+JiL5/8FbTtsUc4bLtPWpb3bLy99Lgc9fN5e670h5f3mtWJl/hZ1Yoh9+sUA6/WaEcfrNCOfxmhXL4zQrl8JsV6n8B0kChbFqT0sEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot the prediction output\n",
    "plt.figure('img 1')\n",
    "plt.imshow(img1, cmap='gray')\n",
    "plt.title('pred:' + str(np.argmax(out_pred[0])), fontsize=22)\n",
    "\n",
    "plt.figure('img 2')\n",
    "plt.imshow(img2, cmap='gray')\n",
    "plt.title('pred:' + str(np.argmax(out_pred[1])), fontsize=22)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:TF1120_GPU]",
   "language": "python",
   "name": "conda-env-TF1120_GPU-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
